import BaseModel from "./BaseModel"
import IBaseIDModel from "../interface/IBaseIDModel"
import { ClickState, FWConfig, GlobalEventName } from "../../tools/Define";

/**
 * 拥有 id type num 三属性的模型的父类
 * 可被 ModelManager 管理
 */
export default class BaseItemModel extends BaseModel implements IBaseIDModel {

    protected clickState: ClickState = ClickState.NOT_CLICK;


    // 数量 [0 - 当前 1 - 旧值]
    protected num:[number, number] = [0, 0];
    protected ID:number;
    protected type:number;

    constructor(ID?, type:number = 0, num:number = 0){
        super();

        this.ID = ID;
        this.type = type;
        this.num[0] = num;
    }
    

    setNum(num) : boolean {
        let updated = false;

        this.num[1] = this.num[0];
        updated = num != this.num[1];

        this.num[0] = num;
        return updated;
    }

    getPreNum() {
        return this.num[1];
    }

    getNum() {
        return this.num[0];
    }

    getDeltaNum() {
        return this.num[0] - this.num[1];
    }

    getType() {
        return this.type;
    }

    setType(t) {
        this.type = t;
    }

    setID(id) {
        this.ID = id;
    }

    getID() {
        return this.ID;
    }


    setClickState(s:ClickState){
        this.clickState = s;
        this.publish(GlobalEventName.ITEM_CHANGE_CLICK_STATE,this);
    }

    getClickState(){
        return this.clickState;
    }
}
